




























function addColumnOrGrouping(iObjectType)
{

var oContextNode = (IsNull(iObjectType)) ? _oSelectedColumnOrGrouping : null;



if (IsNull(iObjectType))
{
iObjectType = getSelectedObjectType();


if (iObjectType == PROPERTY_PAGE_TYPE_GROUP && _oWizardXmlBuilder.GetGroupingCount() >= GROUPING_MAX)
{
iObjectType = PROPERTY_PAGE_TYPE_COLUMN;
oContextNode = null;
}
}
if (IsNull(iObjectType))
{
iObjectType = PROPERTY_PAGE_TYPE_COLUMN;
}


var oArgs = new Object();


var oResult = openPropertyPage(EDIT_MODE_CREATE, iObjectType, oArgs);


if (IsNull(oResult) || IsNull(oResult.Entity))
{
return;
}






if (!IsNull(oResult.Entity.ParentEntity))
{
_oFetchBuilder.AddLinkEntity(oResult.Entity.Name, oResult.Entity.Alias, oResult.Entity.From, oResult.Entity.To, oResult.Entity.ParentEntity);
}


var sAttributeAlias = _oFetchBuilder.AddAttribute(oResult.Entity.Alias, oResult.Attribute);


var sItemId = sAttributeAlias;
var iPosition = (iObjectType == PROPERTY_PAGE_TYPE_GROUP) ? getGroupingIndex(oContextNode) : getColumnIndex(oContextNode);
if (!IsNull(iPosition))
{
iPosition++;
}

if (iObjectType == PROPERTY_PAGE_TYPE_GROUP)
{
_oWizardXmlBuilder.AddGrouping(sAttributeAlias, oResult.SortOrder, oResult.Width, oResult.TimeInterval, oResult.SummaryValue, iPosition);
}
else
{
sItemId = _oWizardXmlBuilder.AddColumn(sAttributeAlias, oResult.Width, oResult.SummaryValue, iPosition);
}


var sDisplayName = getDisplayName(oResult.DisplayName, oResult.TimeInterval);
var oNewSpan = createColumnOrGroupingSpan(iObjectType, sItemId, oResult.DisplayName, sDisplayName, oResult.Width);
if (iObjectType == PROPERTY_PAGE_TYPE_GROUP)
{





var iPosition = (IsNull(oContextNode)) ? _oWizardXmlBuilder.GetGroupingCount() - 1 : getGroupingIndex(oContextNode) + 1;
insertGroupingSpan(oNewSpan, iPosition);
selectOption(oNewSpan.childNodes[0]);
updateGhostGroup();
}
else
{
var oSelectedItemCell = (IsNull(oContextNode)) ? null : oContextNode.parentElement.parentElement;
var oNewColumnCell = createColumnCell(oNewSpan);
insertColumnCell(oNewColumnCell, oSelectedItemCell);
selectOption(oNewColumnCell.childNodes[0].childNodes[0]);
}
}





function convertSpan(sItemId, sTimeInterval, iObjectType)
{

_oSelectedColumnOrGrouping.name = (iObjectType == PROPERTY_PAGE_TYPE_GROUP) ? "Grouping" : "Column";


_oSelectedColumnOrGrouping.id = sItemId;
var oItemLabel = _oSelectedColumnOrGrouping.nextSibling
oItemLabel.htmlFor = sItemId;


oItemLabel.innerText = getDisplayName(oItemLabel.basename, sTimeInterval);
_oSelectedColumnOrGrouping.parentElement.title = getSpanTooltip(iObjectType, oItemLabel.innerText);


oItemLabel.nextSibling.style.display = "none";
}





function createColumnCell(oColumnSpan)
{
var oCell = document.createElement("<td class=\"Column\" />");
oCell.appendChild(oColumnSpan);

return oCell;
}





function createColumnOrGroupingSpan(iObjectType, sId, sDisplayNameBase, sDisplayName, sWidth)
{
var sObjectTypeName = (iObjectType == PROPERTY_PAGE_TYPE_GROUP) ? "Grouping" : "Column";
var sSpanHtml = formatString("<span class=\"ColumnOrGroupingHeader\" style=\"width: {0}px;\" title=\"{1}\"/>", sWidth, getSpanTooltip(iObjectType, sDisplayName));
var oSpan = document.createElement(sSpanHtml);

oSpan.innerHTML = formatString(
"<input type=\"radio\" class=\"HiddenRadio\" name=\"{0}\" id=\"{1}\" onclick=\"selectOption(this)\" />" +
"<label for=\"{1}\" basename=\"{2}\">{3}</label>" +
"<img alt=\"\" src=\"/_imgs/grid/bar_up.gif\" class=\"Sort\" />",
CrmEncodeDecode.CrmHtmlAttributeEncode(sObjectTypeName), CrmEncodeDecode.CrmHtmlAttributeEncode(sId), CrmEncodeDecode.CrmHtmlAttributeEncode(sDisplayNameBase), CrmEncodeDecode.CrmHtmlEncode(sDisplayName));

return oSpan;
}






function editProperties()
{

var iObjectType = getSelectedObjectType();
if (IsNull(iObjectType))
{
return;
}


var oArgs = new Object();



var oWizardXmlNode = null;
var sItemId = _oSelectedColumnOrGrouping.id;
if (iObjectType == PROPERTY_PAGE_TYPE_GROUP)
{
oWizardXmlNode = _oWizardXmlBuilder.GetGrouping(sItemId);




oArgs.TimeInterval = oWizardXmlNode.getAttribute("Interval");
oArgs.SortOrder = oWizardXmlNode.getAttribute("Sort");
}
else
oWizardXmlNode = _oWizardXmlBuilder.GetColumn(sItemId);


var sAttributeAlias = oWizardXmlNode.getAttribute("Field");
oArgs.AttributeAlias = sAttributeAlias;
oArgs.Width = oWizardXmlNode.getAttribute("Width");
oArgs.SummaryValue = oWizardXmlNode.getAttribute("SummaryValue");


var oAttributeInfo = _oFetchBuilder.GetAttributeInfo(sAttributeAlias);
oArgs.Entity = oAttributeInfo.EntityAlias;
oArgs.Attribute = oAttributeInfo.Attribute;


var oResult = openPropertyPage(EDIT_MODE_UPDATE, iObjectType, oArgs);


if (IsNull(oResult) || IsNull(oResult.Entity))
{
return;
}


if (iObjectType == PROPERTY_PAGE_TYPE_GROUP)
{
_oWizardXmlBuilder.UpdateGrouping(_oSelectedColumnOrGrouping.id, oResult.SortOrder, oResult.Width, oResult.TimeInterval, oResult.SummaryValue);
}
else
{
_oWizardXmlBuilder.UpdateColumn(_oSelectedColumnOrGrouping.id, oResult.Width, oResult.SummaryValue);
}


updateColumnOrGroupingSpan(
_oSelectedColumnOrGrouping.parentElement,
getDisplayName(oResult.DisplayName, oResult.TimeInterval),
oResult.Width);
}




function getColumnDisplayName(sColumnId)
{
return Columns.all[sColumnId].nextSibling.innerText;
}





function getColumnIndex(oColumnOption)
{
if (IsNull(oColumnOption))
{
return null;
}

var iPosition = null;
var oColumnCell = oColumnOption.parentElement.parentElement;
for (var i = 0; i < Columns.childNodes.length && IsNull(iPosition); i++)
{
if (Columns.childNodes[i] == oColumnCell)
{
iPosition = i;
}
}
return iPosition;
}




function getDisplayName(sBaseDisplayName, sTimeInterval)
{
if (IsNull(sTimeInterval))
{
return sBaseDisplayName;
}

return formatString(_saGroupingIntervalFormats[sTimeInterval], sBaseDisplayName);
}




function getGroupingUICount()
{

var iMaxGroupingPosition = 0;




for (var i = (GROUPING_MAX - 1); i >= 0; i--)
{
var oGroupingHeaderSpan = getGroupingListItem(i).childNodes[0];
if (oGroupingHeaderSpan.className.indexOf("ColumnOrGroupingHeader") != -1)
{
iMaxGroupingPosition = i;
break;
}
}


return iMaxGroupingPosition + 1;
}





function getGroupingIndex(oGroupingOption)
{
if (IsNull(oGroupingOption))
{
return null;
}

var iPosition = 0;
var oCurrentList = oGroupingOption.parentElement.parentElement.parentElement;
while (oCurrentList.id != "Groupings")
{
iPosition++;
oCurrentList = oCurrentList.parentElement.parentElement;
}
return iPosition;
}




function getGroupingListItem(iIndex)
{
return Groupings.getElementsByTagName("LI")[iIndex];
}




function getSelectedObjectType()
{

if (IsNull(_oSelectedColumnOrGrouping))
{
return null;
}

return (_oSelectedColumnOrGrouping.name == "Grouping") ? PROPERTY_PAGE_TYPE_GROUP : PROPERTY_PAGE_TYPE_COLUMN;
}




function getSpanTooltip(iObjectType, sDisplayName)
{
return formatString((iObjectType == PROPERTY_PAGE_TYPE_GROUP) ? LOCID_TOOLTIP_GROUPING : LOCID_TOOLTIP_COLUMN, sDisplayName);
}




function initializeColumns(oAttributeInfoCache)
{
var oaColumns = _oWizardXmlBuilder.GetColumns();
var saColumnsToRemove = new Array();
for (var i = 0; i < oaColumns.length; i++)
{
var oColumn = oaColumns[i];
var sAttributeAlias = oColumn .getAttribute("Field");
var sDisplayName = oAttributeInfoCache.GetAttributeDisplayName(sAttributeAlias);
if (!IsNull(sDisplayName))
{

var oNewSpan = createColumnOrGroupingSpan(PROPERTY_PAGE_TYPE_COLUMN, oColumn.getAttribute("ID"), sDisplayName, sDisplayName, oColumn.getAttribute("Width"));
insertColumnCell(createColumnCell(oNewSpan), null);
}
else
{



saColumnsToRemove.push(oColumn.getAttribute("ID"));






_oFetchBuilder.RemoveAttribute(sAttributeAlias);



if(_oFetchBuilder.IsSortAttribute(sAttributeAlias))
{
_oFetchBuilder.ClearSorting();
}
}
}


for (var i = 0; i < saColumnsToRemove.length; i++)
{
_oWizardXmlBuilder.RemoveColumn(saColumnsToRemove[i]);
}

return (saColumnsToRemove.length > 0);
}




function initializeGroupings(oAttributeInfoCache)
{
var oaGroupings = _oWizardXmlBuilder.GetGroupings();
var saGroupingsToRemove = new Array();
var oaGroupingSpans = new Array();
for (var i = 0; i < oaGroupings.length; i++)
{
var oGrouping = oaGroupings[i];
var sAttributeAlias = oGrouping.getAttribute("Field");
var sDisplayNameBase = oAttributeInfoCache.GetAttributeDisplayName(sAttributeAlias);
if (!IsNull(sDisplayNameBase))
{


var sDisplayName = getDisplayName(sDisplayNameBase, oGrouping.getAttribute("Interval"));
var oNewSpan = createColumnOrGroupingSpan(PROPERTY_PAGE_TYPE_GROUP, oGrouping.getAttribute("Field"), sDisplayNameBase, sDisplayName, oGrouping.getAttribute("Width"));
oaGroupingSpans.push(oNewSpan);
}
else
{



saGroupingsToRemove.push(sAttributeAlias);






_oFetchBuilder.RemoveAttribute(sAttributeAlias);

}
}


for (var i = 0; i < saGroupingsToRemove.length; i++)
{
_oWizardXmlBuilder.RemoveGrouping(saGroupingsToRemove[i]);
}






for (var i = 0; i < oaGroupingSpans.length; i++)
{
insertGroupingSpan(oaGroupingSpans[i], i);
}



return (saGroupingsToRemove.length > 0);
}




function initializePage()
{

_iLocaleId = WizardGetProperty("Language");


_saGroupingIntervalFormats = getGroupIntervalArray();
_saSummaryValueFormats = getSummaryValueArray();


_oCacheManager = new CacheManager();


var oFetchXml = WizardGetProperty("FetchXml");
_oFetchBuilder = new FetchBuilder();
_oFetchBuilder.LoadXml(oFetchXml);


_oWizardXmlBuilder = new WizardXmlBuilder();
_oWizardXmlBuilder.SetGroupingXml(WizardGetProperty("GroupingXml"));
_oWizardXmlBuilder.SetColumnXml(WizardGetProperty("ColumnXml"));
_oWizardXmlBuilder.SetTableLayoutXml(WizardGetProperty("TableLayoutXml"));



if (_oWizardXmlBuilder.GetColumnCount() > 0 || _oWizardXmlBuilder.GetGroupingCount() > 0)
{

var oAttributeInfoCache = new AttributeInfoCache();
var bDisplayNamesFound = oAttributeInfoCache.Initialize(_oFetchBuilder.GetXml().xml, _iLocaleId);


if (bDisplayNamesFound)
{

var bGroupingsRemoved = initializeGroupings(oAttributeInfoCache);
var bColumnsRemoved = initializeColumns(oAttributeInfoCache);
if (bGroupingsRemoved || bColumnsRemoved)
{
notifications.AddNotification("fieldsRemoved", notifications.GetSeverityEnum().SEVERITYWARNING, "", LOCID_FIELDS_REMOVED);
}


updateSortingUI();
}
}


updateGhostGroup();
}






function insertColumnCell(oNewColumn, oReferenceColumn)
{
if (IsNull(oReferenceColumn))
{
Columns.insertBefore(oNewColumn, GhostColumn)
}
else
{
oReferenceColumn.insertAdjacentElement("afterEnd", oNewColumn);
}
}




function insertGroupingSpan(oNewGroupingSpan, iPosition)
{


var iGroupingCount = getGroupingUICount();
if (iPosition < iGroupingCount)
{
for (var i = iGroupingCount - 1; i >= iPosition; i--)
{
getGroupingListItem(i).childNodes[0].swapNode(getGroupingListItem(i + 1).childNodes[0]);
}
}


var oGroupingListItem = getGroupingListItem(iPosition);
oGroupingListItem.replaceChild(oNewGroupingSpan, oGroupingListItem.childNodes[0]);
}





function move(iDirection)
{


var iObjectType = getSelectedObjectType();
if (IsNull(iObjectType))
{
return;
}



if ((iObjectType == PROPERTY_PAGE_TYPE_GROUP && (iDirection == DIRECTION_LEFT || iDirection == DIRECTION_RIGHT)) ||
(iObjectType == PROPERTY_PAGE_TYPE_COLUMN && iDirection == DIRECTION_DOWN))
{
return;
}


var iPosition = (iObjectType == PROPERTY_PAGE_TYPE_GROUP) ? getGroupingIndex(_oSelectedColumnOrGrouping) : getColumnIndex(_oSelectedColumnOrGrouping);


var sItemId = _oSelectedColumnOrGrouping.id;
switch (iDirection)
{
case DIRECTION_UP:
if (iObjectType == PROPERTY_PAGE_TYPE_COLUMN)
{
var iGroupingCount = _oWizardXmlBuilder.GetGroupingCount();
if (iGroupingCount < GROUPING_MAX)
{

var oColumn = _oWizardXmlBuilder.GetColumn(sItemId);
var sAttributeAlias = oColumn.getAttribute("Field");


var oAttributeInfo = _oFetchBuilder.GetAttributeInfo(sAttributeAlias);
var sTimeInterval = (_oCacheManager.GetFieldDataType(oAttributeInfo.Attribute, oAttributeInfo.Entity, _iLocaleId) == "datetime") ? GROUPING_DEFAULT_TIME_INTERVAL : null;


_oWizardXmlBuilder.AddGrouping(
sAttributeAlias,
GROUPING_DEFAULT_SORT_ORDER,
oColumn.getAttribute("Width"),
sTimeInterval,
GROUPING_DEFAULT_SUMMARY_VALUE,
null);
_oWizardXmlBuilder.RemoveColumn(sItemId);



if (_oFetchBuilder.IsSortAttribute(sAttributeAlias))
{
_oFetchBuilder.ClearSorting();
}


var oColumnSpan = _oSelectedColumnOrGrouping.parentElement;
Columns.removeChild(oColumnSpan.parentElement);


convertSpan(sAttributeAlias, sTimeInterval, PROPERTY_PAGE_TYPE_GROUP);


insertGroupingSpan(oColumnSpan, iGroupingCount);


if ((iGroupingCount + 1) < GROUPING_MAX)
{
updateGhostGroup();
}
}
}
else if (iPosition > 0)
{

_oSelectedColumnOrGrouping.parentElement.swapNode(getGroupingListItem(iPosition - 1).childNodes[0]);


_oWizardXmlBuilder.MoveGrouping(sItemId, iDirection);
}
break;
case DIRECTION_DOWN:
if (iPosition < (_oWizardXmlBuilder.GetGroupingCount() - 1))
{

_oSelectedColumnOrGrouping.parentElement.swapNode(getGroupingListItem(iPosition + 1).childNodes[0]);


_oWizardXmlBuilder.MoveGrouping(sItemId, iDirection);
}
else
{

var oGrouping = _oWizardXmlBuilder.GetGrouping(sItemId)


var sColumnId = _oWizardXmlBuilder.AddColumn(sItemId, oGrouping.getAttribute("Width"), COLUMN_DEFAULT_SUMMARY_VALUE, 0);
_oWizardXmlBuilder.RemoveGrouping(sItemId);


var oGroupingSpan = _oSelectedColumnOrGrouping.parentElement;
removeGroupingSpan(oGroupingSpan);


convertSpan(sColumnId, null, PROPERTY_PAGE_TYPE_COLUMN)


var oColumnCell = createColumnCell(oGroupingSpan);
Columns.insertBefore(oColumnCell, Columns.childNodes[0]);


if (_oWizardXmlBuilder.GetGroupingCount() == (GROUPING_MAX - 1))
{
updateGhostGroup();
}
}
break;
case DIRECTION_LEFT:
case DIRECTION_RIGHT:
if ((iDirection == DIRECTION_LEFT && iPosition > 0) ||
(iDirection == DIRECTION_RIGHT && iPosition < (_oWizardXmlBuilder.GetColumnCount() - 1)))
{

var oColumnCell = _oSelectedColumnOrGrouping.parentElement.parentElement;
var oSwapCell = (iDirection == DIRECTION_LEFT) ? oColumnCell.previousSibling : oColumnCell.nextSibling;
oColumnCell.swapNode(oSwapCell);


_oWizardXmlBuilder.MoveColumn(sItemId, iDirection);
}
break;
}



_oSelectedColumnOrGrouping.checked = true;
}




function moveNext()
{

if (_oWizardXmlBuilder.GetColumnCount() == 0)
{
alert(LOCID_NO_COLUMNS_SELECTED);
return;
}



if (_oWizardXmlBuilder.GetTableWidth() > PAGE_WIDTH_PIXELS && !confirm(LOCID_PAGEBREAK_WARNING))
{
return;
}


WizardSetProperty("FetchXml", _oFetchBuilder.GetXml());


WizardSetProperty("GroupingXml", _oWizardXmlBuilder.GetGroupingXml());
WizardSetProperty("ColumnXml", _oWizardXmlBuilder.GetColumnXml());
WizardSetProperty("TableLayoutXml", _oWizardXmlBuilder.GetTableLayoutXml());

WizardNavigate(_WizardNavigateEnum.NEXT);
}





function openPropertyPage(iMode, iType, oArgs)
{

var oStringBuilder = new StringBuilder();


oStringBuilder.Append(prependOrgName("/CRMReports/AdHocWizard/PropertyPageDialog.aspx?"));


oStringBuilder.Append("lcid=");
oStringBuilder.Append(CrmEncodeDecode.CrmUrlEncode(_iLocaleId));


oStringBuilder.Append("&primary=");
oStringBuilder.Append(CrmEncodeDecode.CrmUrlEncode(_oFetchBuilder.GetPrimaryEntityName()));


var sSecondaryEntityName = _oFetchBuilder.GetSecondaryEntityName();
if (!IsNull(sSecondaryEntityName))
{
oStringBuilder.Append("&secondary=");
oStringBuilder.Append(CrmEncodeDecode.CrmUrlEncode(sSecondaryEntityName));
}


oStringBuilder.Append("&mode=");
oStringBuilder.Append(CrmEncodeDecode.CrmUrlEncode(iMode));


oStringBuilder.Append("&type=");
oStringBuilder.Append(CrmEncodeDecode.CrmUrlEncode(iType));


if (IsNull(oArgs))
{
oArgs = new Object();
}
oArgs.Cache = _oCacheManager;
oArgs.EditMode = iMode;
oArgs.ObjectType = iType;




var oaFieldExclusionList = _oFetchBuilder.GetAttributeInfos(_oWizardXmlBuilder.GetAttributeAliases(iType));
if (iMode == EDIT_MODE_UPDATE)
{
oaFieldExclusionList[IsNull(oArgs.Entity) ? "" : oArgs.Entity][oArgs.Attribute] = null;
}
oArgs.FieldExclusionList = oaFieldExclusionList;


var oResult = openStdDlg(oStringBuilder.ToString(), oArgs, 500, 375, false);


if (!IsNull(oResult))
{
_oCacheManager = oResult.Cache;
}


return oResult;
}




function remove()
{


var iObjectType = getSelectedObjectType();
if (IsNull(iObjectType))
{
return;
}



if (iObjectType == PROPERTY_PAGE_TYPE_COLUMN &&
WizardHasProperty("ColumnXml") &&
!confirm(LOCID_REMOVE_COLUMN_WARNING))
{
return;
}


var sItemId = _oSelectedColumnOrGrouping.id;
var sAttributeAlias = (iObjectType == PROPERTY_PAGE_TYPE_GROUP) ? sItemId : _oWizardXmlBuilder.GetColumn(sItemId).getAttribute("Field");
var bRemoveAttribute = (iObjectType == PROPERTY_PAGE_TYPE_GROUP) ? _oWizardXmlBuilder.RemoveGrouping(sItemId) : _oWizardXmlBuilder.RemoveColumn(sItemId);



if (iObjectType == PROPERTY_PAGE_TYPE_COLUMN && _oFetchBuilder.IsSortAttribute(sAttributeAlias))
{
_oFetchBuilder.ClearSorting();
}



if (bRemoveAttribute)
{
_oFetchBuilder.RemoveAttribute(sAttributeAlias);
}


if (iObjectType == PROPERTY_PAGE_TYPE_GROUP)
{
removeGroupingSpan(_oSelectedColumnOrGrouping.parentElement);



if (_oWizardXmlBuilder.GetGroupingCount() == GROUPING_MAX - 1)
{
updateGhostGroup();
}
}
else
{
Columns.removeChild(_oSelectedColumnOrGrouping.parentElement.parentElement);
}


_oSelectedColumnOrGrouping = null;
}




function removeGroupingSpan(oGroupingSpan)
{

var iPosition = getGroupingIndex(oGroupingSpan.childNodes[0]);


var oBlankSpan = document.createElement("<span class=\"EmptyGhostHeader\"></span>");
oGroupingSpan.parentElement.replaceChild(oBlankSpan, oGroupingSpan);




for (var i = iPosition + 1; i < GROUPING_MAX; i++)
{
var oGroupingSpan = getGroupingListItem(i).childNodes[0];
var oSwapSpan = getGroupingListItem(i - 1).childNodes[0];
oGroupingSpan.swapNode(oSwapSpan);
}
}




function selectOption(oColumnOrGrouping)
{

if (!IsNull(_oSelectedColumnOrGrouping))
{
_oSelectedColumnOrGrouping.checked = false;
_oSelectedColumnOrGrouping.parentElement.className = "ColumnOrGroupingHeader";
}



oColumnOrGrouping.checked = true;
oColumnOrGrouping.parentElement.className = "ColumnOrGroupingHeader SelectedColumnOrGroupingHeader";


_oSelectedColumnOrGrouping = oColumnOrGrouping;
}





function setFilter()
{


var iObjectType = (_oWizardXmlBuilder.GetGroupingCount() > 0) ? PROPERTY_PAGE_TYPE_GROUP : PROPERTY_PAGE_TYPE_COLUMN;

var oaFilterColumns = new Array();
if (iObjectType == PROPERTY_PAGE_TYPE_GROUP)
{
var oaSummaryValueColumns = _oWizardXmlBuilder.GetColumnsWithSummaryValues();
for (var i = 0; i < oaSummaryValueColumns.length; i++)
{
var oSummaryValueColumn = oaSummaryValueColumns[i];


var oFilterColumn = new Object();
oFilterColumn.ColumnId = oSummaryValueColumn.getAttribute("ID");



var sSummaryValueFormat = _saSummaryValueFormats[oSummaryValueColumn.getAttribute("SummaryValue")];
oFilterColumn.DisplayName = formatString(sSummaryValueFormat, getColumnDisplayName(oFilterColumn.ColumnId));


oaFilterColumns.push(oFilterColumn);
}


if (oaFilterColumns.length == 0)
{
alert(LOCID_NO_FILTERABLE_GROUPING);
return;
}
}
else
{
var oaColumns = _oWizardXmlBuilder.GetColumns();
for (var i = 0; i < oaColumns.length; i++)
{
var oColumn = oaColumns[i];
var oAttributeInfo = _oFetchBuilder.GetAttributeInfo(oColumn.getAttribute("Field"));

if (isNumericDataType(_oCacheManager.GetFieldDataType(oAttributeInfo.Attribute, oAttributeInfo.Entity, _iLocaleId)))
{


var oFilterColumn = new Object();
oFilterColumn.ColumnId = oColumn.getAttribute("ID");
oFilterColumn.DisplayName = getColumnDisplayName(oFilterColumn.ColumnId);
oaFilterColumns.push(oFilterColumn);
}
}


if (oaFilterColumns.length == 0)
{
alert(LOCID_NO_FILTERABLE_COLUMN);
return;
}
}


var oArgs = new Object();
oArgs.FilterColumns = oaFilterColumns;
oArgs.ObjectType = iObjectType;
oArgs.ScopeDisplayName = (iObjectType == PROPERTY_PAGE_TYPE_GROUP) ? getGroupingListItem(0).childNodes[0].childNodes[1].innerText : null;

var oFilterNode = _oWizardXmlBuilder.GetTableFilterNode();
var bFilterExists = !IsNull(oFilterNode);
oArgs.FilterColumn = (bFilterExists) ? oFilterNode.getAttribute("Column") : null;
oArgs.FilterOperator = (bFilterExists) ? oFilterNode.getAttribute("Operator") : null;
oArgs.FilterValue = (bFilterExists) ? oFilterNode.getAttribute("FilterValue") : null;


var aFilter = openStdDlg(prependOrgName(formatString("/CRMReports/AdHocWizard/FilterDialog.aspx?lcid={0}&primary={1}&type={2}", CrmEncodeDecode.CrmUrlEncode(_iLocaleId), CrmEncodeDecode.CrmUrlEncode(_oFetchBuilder.GetPrimaryEntityName()), CrmEncodeDecode.CrmUrlEncode(iObjectType))), oArgs, 450, 300);
if (IsNull(aFilter))
{
return;
}



if (IsNull(aFilter[1]))
{
_oWizardXmlBuilder.ClearTableFilter();
}
else
{
_oWizardXmlBuilder.SetTableFilter(aFilter[0], aFilter[1], aFilter[2]);
}
}





function setSort()
{

var saAttributeAliases = _oFetchBuilder.GetPrimaryEntityAttributeAliases();



var oaSortColumns = new Array();
for (var i = 0; i < saAttributeAliases.length; i++)
{
var sAttributeAlias = saAttributeAliases[i];
var oColumn = _oWizardXmlBuilder.GetColumnByAttributeAlias(sAttributeAlias);
if (!IsNull(oColumn))
{
var oSortColumn = new Object();
oSortColumn.AttributeAlias = sAttributeAlias;
oSortColumn.DisplayName = getColumnDisplayName(oColumn.getAttribute("ID"));
oaSortColumns.push(oSortColumn);
}
}



if (oaSortColumns.length == 0)
{
alert(LOCID_NO_SORTABLE_COLUMNS);
return;
}


var oArgs = new Object();
oArgs.SortColumns = oaSortColumns;


var oSortNode = _oFetchBuilder.GetSortNode();
var bIsSorted = !IsNull(oSortNode);
oArgs.SortAttribute = (bIsSorted) ? oSortNode.getAttribute("attribute") : null;
oArgs.SortDescending = (bIsSorted) ? (oSortNode.getAttribute("descending") == "true") : false;


var aSetSort = openStdDlg(prependOrgName("/CRMReports/AdHocWizard/SetSortDialog.aspx"), oArgs, 375, 250);
if (!IsNull(aSetSort))
{

if (IsNull(aSetSort[1]))
{
_oFetchBuilder.ClearSorting();
}
else
{
_oFetchBuilder.SetSortAttribute(aSetSort[1], aSetSort[0] ? "true" : "false")
}


updateSortingUI();
}
}





function updateColumnOrGroupingSpan(oSpan, sDisplayName, sWidth)
{

oSpan.style.width = formatString("{0}px", sWidth);


oSpan.childNodes[1].innerText = sDisplayName;




oSpan.title = getSpanTooltip(getSelectedObjectType(), sDisplayName)
}





function updateGhostGroup()
{
var iGroupingCount = _oWizardXmlBuilder.GetGroupingCount();
if (iGroupingCount < GROUPING_MAX)
{
var oGhostSpan = document.createElement("<span class=\"GhostHeader\" />");
oGhostSpan.innerHTML = formatString("<a href=\"javascript:addColumnOrGrouping(PROPERTY_PAGE_TYPE_GROUP)\" title=\"{0}\" id=\"GhostGroup\">{1}</a>", CrmEncodeDecode.CrmHtmlAttributeEncode(LOCID_GHOST_GROUPING), CrmEncodeDecode.CrmHtmlEncode(LOCID_GHOST_GROUPING));
insertGroupingSpan(oGhostSpan, iGroupingCount);
}
}




function updateSortingUI()
{
var oSortNode = _oFetchBuilder.GetSortNode();
var bDescending = false;
var sSortColumnId = null;
if (!IsNull(oSortNode))
{
bDescending = (oSortNode.getAttribute("descending") == "true");
sSortColumnId = _oWizardXmlBuilder.GetColumnByAttributeAlias(oSortNode.getAttribute("attribute")).getAttribute("ID");
}



for (var i = 0; i < Columns.childNodes.length - 1; i++)
{
var oColumnSpan = Columns.childNodes[i].childNodes[0];
var oSortImage = oColumnSpan.childNodes[2];
if (oColumnSpan.childNodes[0].id == sSortColumnId)
{
oSortImage.alt = (bDescending) ? LOCID_ALT_COLUMNSORTORDER_DOWN : LOCID_ALT_COLUMNSORTORDER_UP;
with (oSortImage.style)
{
display = "inline";
filter = (bDescending) ? "flipv()" : "";
}
}
else
{
oSortImage.style.display = "none";
oSortImage.alt = "";
}
}
}